package com.coder520.attend.controller;

import com.coder520.attend.entity.Attend;
import com.coder520.attend.service.AttendService;
import com.coder520.attend.vo.QueryCondition;
import com.coder520.common.page.PageQueryBean;
import com.coder520.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017-7-8.
 */
@Controller
@RequestMapping("attend")
public class AttendController {

    @Autowired
    private AttendService attendService;

    @RequestMapping
    public String toAttend(){

        return "attend";
    }


    /**
      *@Author Jay
      *@Date 2017-7-9 17:17
      *@Description  添加测试表
      */
    @RequestMapping("/signAttend")
    @ResponseBody
    public String signAttend(@RequestBody Attend attend) throws Exception {
        attendService.signAttend(attend);
        return "succ";
    }

    /**
      *@Author Jay
      *@Date 2017-7-10 18:10
      *@Description  考勤数据分布查询
      */
    @RequestMapping("/listAttend")
    @ResponseBody
    public PageQueryBean listAttend(QueryCondition condition,HttpSession session) {
        User user = (User) session.getAttribute("userInfo");
        condition.setUserId(user.getId());
        //condition.setUserId(1L);
        String[] rangeDate = condition.getRangeDate().split("/");
        condition.setStartDate(rangeDate[0]);
        condition.setEndDate(rangeDate[1]);

        PageQueryBean reslut = attendService.listAttend(condition);
        return reslut;
    }

}
